package com.jd.myaaaccount.util;

import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Bitmap.CompressFormat;
import android.media.ThumbnailUtils;

public class BitmapHelper {
	/**
	 * 压缩的图片
	 */
	public static byte[] compressPiture(byte[] arg0) {
		if (arg0 == null)
			return null;
		Bitmap bmp = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
		if (bmp != null) {
			// 旋转
			Matrix max = new Matrix();
			max.postRotate(90.0f);
			bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
					bmp.getHeight(), max, false);
			// 压缩
			bmp = ThumbnailUtils.extractThumbnail(bmp, bmp.getWidth() / 2,
					bmp.getHeight() / 2);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			bmp.compress(CompressFormat.JPEG, 80, baos);
			return baos.toByteArray();
		} else
			return null;
	}
}
